package com.lvyq.myplayer.model.index

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.lvyq.myplayer.net.api.indexDailyPlayApiService
import kotlinx.coroutines.launch

/**
 * 文件描述：IndexLastSongModel
 * 作者：lvyq
 * 创建时间：2025-03-28
 * 修改时间：2025-03-28
 */
class IndexLastSongModel: ViewModel() {
    private val _data = MutableLiveData<IndexLastSongBean>()
    val data: LiveData<IndexLastSongBean> = _data


    fun getLastSongLst() {
        Thread.sleep(50)
        viewModelScope.launch {
            try {
                // 使用协程发起网络请求
                val response = indexDailyPlayApiService.getLastSongLst()
                if (response.isSuccessful) {
                    _data.value = response.body()
                } else {
                    // 处理错误
                    Log.e("IndexLastSongModel", "Error: ${response.code()}")
                }
            } catch (e: Exception) {
                // 处理异常
                Log.e("IndexLastSongModel", "Exception: ${e.message}")
            }
        }
    }
}